package cn.itzzx.transfer.service.impl;

import cn.itzzx.annotation.Autowired;
import cn.itzzx.annotation.Service;
import cn.itzzx.annotation.Transactional;
import cn.itzzx.transfer.dao.AccountDao;
import cn.itzzx.transfer.pojo.Account;
import cn.itzzx.transfer.service.TransferService;

/**
 * @author 应癫
 */

@Service(value = "transferService")
public class TransferServiceImpl implements TransferService{

	@Autowired
	private AccountDao accountDao;

	@Transactional
	@Override
	public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {
		Account from = accountDao.queryAccountByCardNo(fromCardNo);
		Account to = accountDao.queryAccountByCardNo(toCardNo);

		from.setMoney(from.getMoney() - money);
		to.setMoney(to.getMoney() + money);

		accountDao.updateAccountByCardNo(to);
		int c = 1 / 0;
		accountDao.updateAccountByCardNo(from);
	}
}
